#!/usr/bin/env python
# encoding: utf-8

import re
import codecs

def main(env):
	count = 0
	result = {}
	for (category,d) in env.items():
		items = sorted(((" "+k if k.startswith("cw") else k),v) for (k,v) in d.items())
		if items:
			items = [(k.lstrip(),v) for (k,v) in items]
			pad = max(len(k) for (k,_) in items) + 2
			l = []
			for (key,value) in items:
				k = ("'%s'" % key).ljust(pad)
				if key.endswith("Masked") and value:
					value = env["constants"]["passwordMask"]
				l.append('  %s : %s,' % (k,repr(value)))
			count += len(l)
			result[category] = "\n".join(l)
		else:
			result[category] = ""
	text = codecs.open("%s_template.txt" % env["constants"]["language"],"r","utf8").read() % result
	return [("textBox", {
				"text":text,
				"width":640,
				"height":480,
				"label":env["static"]["cwEnvironment_label"] % count
			})]
